
import detailList from '../utils/detailList'
import MiddleFunction from '../tool/middleFuction'
import '../assets/style/toolTip.less'
//展示详情
const flagDetail = detailList.reduce((arr:string[],val)=>{
  arr.push(val.name)
  return arr
},[])
//初始化函数
export const getOption = (newCashData:Array<any>)=>{
  return {
    // backgroundColor: "#02246d",
    tooltip: {
      trigger: "item",
      triggerOn:'click',
      formatter: function(params:{name:string}){
        if(!flagDetail.includes(params.name)) return `<div style="width:0;"><div>`;
        return `<div class="tooltipWrap">${detailList.filter(val=> val.name === params.name)[0].detail}</div>`
      },
       extraCssText:'white-space:pre-wrap;background-color:transparent;border-color:transparent;box-shadow:none;'
    },
    toolbox: {
      show:false,
      feature: {
        dataZoom: {
          yAxisIndex: false
        },
        restore: {},
        saveAsImage: {}
      }
    },
    series: [
      {
        type: "tree",
        // edgeShape:"polyline",
        name: "",
        data: newCashData,
        layout: 'orthogonal', // or 'force'
        top: "0",
        left: "100",
        roam: true,
        zoom:1,
        symbolKeepAspect: true,
        initialTreeDepth:2,
        label: {
            position: "center",
            verticalAlign: "middle",
            borderRadius: 6,
            align: "center",
            padding: [6,8],
            shadowColor: 'rgba(0, 0, 0, 0.5)', // 设置阴影颜色
            shadowBlur: 3, // 添加整个 label 区域的阴影效果
            backgroundColor: {
              type: 'linear',
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: [
                { offset: 0, color: '#20407d' },
                { offset: 1, color: '#386fc5' }
              ]
            },
            color: "#fff",
            formatter:function(params:{name:string}){
            let labelName = params.name === '12309检察服务中心信、访、网、电    一站式接收'? '12309检察服务中心信、访、网、电    一站式接收' : params.name.replace(/\d/g, '')
            let chartLabel =  MiddleFunction.addNewlineEveryTenCharacters(labelName)
            return `{a|${chartLabel}}{b|${flagDetail.includes(params.name) ? '📋' : ""}}`
            },
            rich: {
              a: {
                fontSize: 20,
                // color: "#fff",
                align: "left",
                lineHeight: 23,
                fontFamily: 'Microsoft YaHei',  
              },
              b:{
                fontSize: 20,
                color: '#ff7800',
                align: "left",
                padding: [0, 5, 0, 5], // 调整图标的点击区域
                onclick: function () {
                  // 点击图标时触发的事件
                }
                
              }
            },
        },
        leaves: {
          // label: {
          //   borderRadius: 4,
          //   normal: {
          //     position: "center",
          //     verticalAlign: "middle",
          //     align: "left",
          //     // backgroundColor: "#c44eff",
          //     formatter: ["{box|{b}}"].join("\n"),
          //     rich: {
          //       box: {
          //         color: "#fff",
          //         padding: [2, 2],
          //         align: "center",
          //       },
          //     },
          //   },
          // },
        },
        emphasis: {
          focus: 'relative',
        },
        expandAndCollapse: false,
        animationDuration: 700,
        animationDurationUpdate: 500,
        lineStyle: {
          color: {
            type:"linear",
            colorStops:[
              { offset: 0, color: '#b2cbd8' },    // 0% 处的颜色
              { offset: 1, color: '#b4cedd' }, // 50% 处的颜色
            ],
            global: false // 缺省为 false
          }, // 设置节点之间连线的颜色
          width: 6 // 设置节点之间连线的宽度
        }
      },
    ],
  }
} 

